import _ from 'lodash';
export const chart1_lable = [
  {
    type: '系统负荷-联络线：',
    key: 'k1',
    color: '#FF0000',
  },
  {
    type: '火电最小：',
    key: 'k3',
    color: '#7f7f7f',
  },
  {
    type: '水电计划：',
    key: 'k4',
    color: '#50ad5c',
  },
  {
    type: '新能源预测：',
    key: 'k5',
    color: '#bfdde7',
  },
  {
    type: '火电可调：',
    key: 'k2',
    color: '#ffff53',
  },
];
export const chart2_lable = [
  {
    bg: '#e6bbbb',
    label: '峰时段',
  },
  {
    bg: '#6a94d2',
    label: '平时段',
  },
  {
    bg: '#dddb9f',
    label: '谷时段',
  },
];
const markAreaColor = {
  high: 'rgba(230,187,187,0.1)',
  middle: 'rgba(106,148,210,0.1)',
  low: 'rgba(221,219,159,0.1)',
};
const markArea = [
  {
    start: '00:00',
    color: markAreaColor.low,
    end: '07:00',
  },
  {
    start: '07:00',
    color: markAreaColor.high,
    end: '09:00',
  },
  {
    start: '09:00',
    color: markAreaColor.middle,
    end: '17:00',
  },
  {
    start: '17:00',
    color: markAreaColor.high,
    end: '23:00',
  },
  {
    start: '23:00',
    color: markAreaColor.low,
    end: '24:00',
  },
];
export const chart1 = (param, ctooltip) => {
  let dataSource = [];
  Array.from({ length: 24 }, (__, i) => {
    let t = i + 1;
    let obj = {
      time: `${t > 9 ? String(t) : `0` + String(t)}:00`,
      k1: param.curveData[t]?.toFixed(2) || 0,
      k2: param?.areaData[t]?.thermalPowerAdjustable.toFixed(2) || 0,
      k3: param?.areaData[t]?.fireMin.toFixed(2) || 0,
      k4: param?.areaData[t]?.hydrolicPlan.toFixed(2) || 0,
      k5: param?.areaData[t]?.newEnergySourceForecast.toFixed(2) || 0,
    };
    dataSource.push(obj);
  });
  let tooltip = {
    trigger: 'axis',
    extraCssText: 'box-shadow: 0 0 10px rgba(0, 0, 0, 0.1)',
    backgroundColor: 'rgba(255, 255, 255, 1)',
    textStyle: { color: '#888E95', borderWidth: 1, borderColor: '#1A253C4B', padding: 12 },
  };
  tooltip.axisPointer = {
    type: 'cross',
    label: { backgroundColor: '#F5F8FA', color: '#888E95', shadowBlur: 0 },
  };
  tooltip.formatter = ctooltip;
  // options
  return {
    animation: false,
    dataset: {
      dimensions: ['time', 'k1', 'k3', 'k4', 'k5', 'k2'],
      source: dataSource,
    },
    grid: { top: 30, left: 48, bottom: 56, right: 48 },
    tooltip: tooltip,
    legend: {},
    xAxis: [{ type: 'category', boundaryGap: false }],
    yAxis: [{ type: 'value', name: null }],
    series: [
      {
        type: 'line',
        name: '系统负荷-联络线',
        color: '#FF0000',
        props: { z: 10 },
      },
      {
        type: 'line',
        name: '火电最小',
        color: '#7f7f7f',
        props: { stack: 'A', areaStyle: { opacity: 1 } },
      },
      {
        type: 'line',
        name: '水电计划',
        color: '#50ad5c',
        props: { stack: 'A', areaStyle: { opacity: 1 } },
      },
      {
        type: 'line',
        name: '新能源预测',
        color: '#bfdde7',
        props: { stack: 'A', areaStyle: { opacity: 1 } },
      },
      {
        type: 'line',
        name: '火电可调',
        color: '#ffff53',
        props: { stack: 'A', areaStyle: { opacity: 1 } },
      },
    ],
  };
};

export const chart2 = (param) => {
  let dataSource = [];
  for (var key in param) {
    dataSource.push({
      time: key,
      k1: param[key]?.dayahead_price?.toFixed(2) || 0,
      k2: param[key]?.realtime_price?.toFixed(2) || 0,
    });
  }
  // options
  return {
    animation: false,
    dataset: {
      dimensions: ['time', 'k1', 'k2'],
      source: dataSource,
    },
    grid: { top: 8, left: 28, bottom: 56, right: 48 },
    tooltip: {},
    legend: {},
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        formatter: (value, index) => {
          if (value.slice(-2) == '00' && Number(value.slice(0, 2)) % 2 === 0) {
            return value;
          } else {
            return '';
          }
        },
      },
    ],
    yAxis: [{ type: 'value', name: '' }],
    series: [
      {
        type: 'line',
        name: '日前电价',
        color: '#6a94d2',
        props: {
          smooth: true,
          markArea: {
            data: markArea.map((item) => {
              return [
                {
                  name: '',
                  xAxis: item.start,
                  itemStyle: {
                    color: item.color,
                  },
                },
                {
                  xAxis: item.end,
                },
              ];
            }),
          },
        },
      },
      {
        type: 'line',
        name: '实时电价',
        color: '#e04137',
        props: {
          smooth: true,
        },
      },
    ],
  };
};
